﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.AuthorizationServices.Dtos
{
    public class AccountInfo
    {
        public long Id { get; set; }

        public string UserName { get; set; }

        /// <summary>
        /// 当前账户昵称
        /// </summary>

        public string NickName { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 是否具有本地邮箱
        /// </summary>
        public bool LocalEmail { get; set; }

        /// <summary>
        /// 是否为超级管理员
        /// </summary>
        public bool IsSuperAdmin
        {
            get
            {
                return (Id == 1 && IsLocalAccount);
            }
        }

        /// <summary>
        /// 角色
        /// </summary>
        public List<string> Roles { get; set; }

        /// <summary>
        /// 接口权限
        /// </summary>
        public List<string> Permissions { get; set; }

        /// <summary>
        /// 功能权限
        /// </summary>
        public List<string> Features { get; set; }

        /// <summary>
        /// 账户提供商
        /// </summary>
        public string Provider { get; set; }

        /// <summary>
        /// 是否为本地账户
        /// </summary>
        public bool IsLocalAccount
        {
            get
            {
                return (string.IsNullOrEmpty(Provider) || string.Equals(Provider, "Local"));
            }
        }


        public bool HasPermission(string permission)
        {
            return IsSuperAdmin || string.IsNullOrEmpty(permission) || (Permissions?.Contains(permission) ?? false);
        }

        /// <summary>
        /// 相关信息
        /// </summary>
        public IpInfo IpInfo { get; set; }
    }

    public class IpInfo()
    {
        /// <summary>
        /// 当前ip地址
        /// </summary>
        public string Ip { get; set; }

        /// <summary>
        /// 登录地址
        /// </summary>
        public string Address { get; set; }
    }
}

